package com.pubinfo.passbook.common.model.bo.bank;

import cn.hutool.core.date.DateUtil;
import com.pubinfo.passbook.common.config.ApplicationConfig;
import com.pubinfo.passbook.common.utils.bank.BankAesUtil;
import com.pubinfo.passbook.common.utils.bank.BankSignUtil;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

@NoArgsConstructor
@Data
public class BankBillBase implements Serializable {
  
  private static final long serialVersionUID = 1L;
  //请求ID,1小时内不能重复 32
  private String requestId;
  private String appKey; //应用标识
  private String time; //时间（格式: yyyyMMddHHmmss）
  private String method; //接口方法名称，详见接口名称
  private String content;  //参数内容
  private String sign;  //签名串
  
  /**
   * @param method
   * @param content 参数的json格式
   */
  public BankBillBase(ApplicationConfig.Bank bank, Method method, String content) {
    String date = DateUtil.format(new Date(), "yyyyMMddHHmmss");
    String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 32);
    this.requestId = uuid;
    this.time = date;
    this.method = method.name();
    this.content = BankAesUtil.encrypt(bank.getAPPSecret(), content);
    this.sign = BankSignUtil.getSignature(this.content + uuid + date, bank.getAPPSecret());
    this.appKey = bank.getAppKey();
  }
  
  public enum Method {
    apply_receipt, query_receipt
  }
}
